home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 26
/
Cream of the Crop 26.iso
/
program
/
ddj0897.zip
/
RCSC.ZIP
/
LIB51
/
ITOX.C
< prev
next >
Wrap
Text File
|
1997-01-12
|
619b
|
24 lines
/*
** itox -- converts nbr to hex string of length sz
** right adjusted and blank filled, returns str
**
** if sz > 0 terminate with null byte
** if sz = 0 find end of string
** if sz < 0 use last byte for data
*/
itox(nbr, str, sz) int nbr; char str[]; int sz; {
int digit, offset;
if(sz>0) str[--sz]=0;
else if(sz<0) sz = -sz;
else while(str[sz]!=0) ++sz;
while(sz) {
digit=nbr&15; nbr=(nbr>>4)&4095;
if(digit<10) offset=48; else offset=55;
str[--sz]=digit+offset;
if(nbr==0) break;
}
while(sz) str[--sz]=' ';
return str;
}